defmodule ChoicePlayground.Question do
  use ChoicePlayground.Web, :model

  schema "questions" do
    field :seq, :integer
    field :type, :string
    field :title, :string
    field :required, :boolean, default: false
    belongs_to :questionnaire, ChoicePlayground.Questionnaire

    has_many :question_content, ChoicePlayground.QuestionContent
    timestamps()
  end

  @doc """
  Builds a changeset based on the `struct` and `params`.
  """
  def changeset(struct, params \\ %{}) do
    struct
    |> cast(params, [:type, :seq, :title, :required])
    |> validate_required([:type, :seq, :title, :required])
  end
end
